package itbour.onetouchshow.fragment.challengezone;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;

import com.google.gson.Gson;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import butterknife.BindView;
import itbour.onetouchshow.R;
import itbour.onetouchshow.base.mvp.MVPBaseFragment;
import itbour.onetouchshow.bean.V_1_3HomePageDataBean;
import itbour.onetouchshow.bean.page.Page;
import itbour.onetouchshow.utils.OneTouchHeader;


public class ChallengeZoneListFragment extends MVPBaseFragment<ChallengeZoneListContract.View, ChallengeZoneListPresenter> implements ChallengeZoneListContract.View {

    public static final int ON_REFRESH = 1;
    public static final int ON_LOAD = 2;
    public int mPageIndex = 0;
    public int pullStatus;
    @BindView(R.id.id_recyclerview)
    RecyclerView idRecyclerview;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout mRefreshLayout;
    OneTouchHeader mClassicsHeader;
    Page page;

    @Override
    protected void initView() {
        onLoadData();
        mClassicsHeader = (OneTouchHeader) mRefreshLayout.getRefreshHeader();
        //隐藏时间
        mClassicsHeader.setEnableLastTime(false);
        mRefreshLayout.getLayout().setBackgroundResource(android.R.color.transparent);
        mRefreshLayout.setPrimaryColors(0, 0xff666666);
        mRefreshLayout.setEnableAutoLoadMore(true);
        mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                pullStatus = ON_REFRESH;
                if (mPresenter != null) {
                    page.loadPage(true);
                }
                // refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败
            }
        });
        mRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshlayout) {
                //  refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
                pullStatus = ON_LOAD;
                if (mPresenter != null) {
                    page.loadPage(false);
                }

            }
        });
        initRecycleView();
    }


    public void onLoadData() {
        page = new Page() {
            @Override
            public void load(int param1, int param2) {
                mPageIndex = param1;

                mPresenter.getHomepageInfo();
            }
        };
        pullStatus = ON_REFRESH;
        page.loadPage(true);
    }


    private void initRecycleView() {


    }


    @Override
    protected int getLayoutId() {
        return R.layout.challzonelist_layout;
    }

    @Override
    protected void afterCreate(Bundle bundle) {

    }

    @Override
    public void loadSucceed(String result) {
        //请求后台数据
        V_1_3HomePageDataBean dataBean = new Gson().fromJson(result, V_1_3HomePageDataBean.class);
        //setHomePageData(dataBean);
    }

    @Override
    public void loadFaild(String error) {

    }

}
